package 一六;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * Created by lenovo on 2017/3/14.
 */
public class q3 {

    private static int count = 0;

    /**
     * 递归生成组合字符串
     * @param source
     * @param result
     */
    private static void fullPermution(Vector<Character> source,Vector<Character> result){
        if(source.size() == 0){
            String str = "";
            for(int i=0;i<result.size();i++){
                str+=result.elementAt(i);
            }

            if (q3.panDuan(str)) {
                System.out.println(str);
                count++;
            }
            return;
        }

        for(int i=0;i<source.size();i++){
            Vector<Character> tsource = new Vector<>(source);
            Vector<Character> tresult = new Vector<>(result);
            tresult.add(source.elementAt(i));
            tsource.remove(i);
            new q3().fullPermution(tsource,tresult);
        }
    }

    /**
     * 判断是否满足需要条件
     * @param str
     * @return
     */
    private static Boolean panDuan(String str){

        int A = Integer.parseInt(str.substring(0,1));
        double B = Double.parseDouble(str.substring(1,2));
        double C = Double.parseDouble(str.substring(2,3));
        double DEF= Double.parseDouble(str.substring(3,6));
        double GHI= Double.parseDouble(str.substring(6,9));

        return A + B/C + DEF/GHI  == 10?Boolean.TRUE:Boolean.FALSE;
    }

    public  static void main(String[] args){
        Vector<Character> sourse = new Vector<>();
        Vector<Character> result = new Vector<>();

        for(int i =1;i<=9;i++){
            sourse.add((char)('0'+i));
        }

        q3.fullPermution(sourse,result);
        System.out.println(count);
    }
}
